package com.redis.lock;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Description
 * @Author lizhilong
 * @Date 2020/12/9 13:50
 */
@Slf4j
@Component
public class KeyGeneratorSelector {


    @Resource
    private ApplicationContext applicationContext;


    public KeyGenerator getKeyGenerator(Class<? extends KeyGenerator> clazz) {
        Map<String, KeyGenerator> beansOfType = applicationContext.getBeansOfType(KeyGenerator.class);
        return beansOfType.values().stream().filter(e -> e.getClass().equals(clazz)).findFirst().orElse(null);
    }
}
